<%@ page import="java.util.*"%>
<%@ page import="Model.Wall.*"%>
<%@ page import="DBAccess.DBAccess"%>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.SQLException"%>
		<div id='contents'>

			<!-- WALL MESSAGES -->
			<%
			int profileID2 = -1;
			String profileIDF = "";
			if (session.getAttribute("toID")!=null){
				//System.out.println("toID not null:" + session.getAttribute("toID"));
				profileID2 =(Integer) session.getAttribute("toID");
			}
				
			//System.out.println("profileID2:" + profileID2);
			
				Wall wall = new Wall();
				String cmd = "Select W.userID, W.postID, W.message, W.posttime, W.fromID, A.name from walldb W, accountdb A"
						+ " Where W.userID = '"+profileID2+ "' AND W.fromID = A.userID order by postID desc";

				PreparedStatement ps = null;
				ResultSet rs = null;
				int postID = -1;
				String message = null;
				int posttime = -1;
				int fromID = -1;
				String name2 ="";
				
				//System.out.println(wall.getNumMessages(profileID2));
				for (int i = 1; i < wall.getNumMessages(profileID2) + 1; i++) {
					try {
						ps = DBAccess.con.prepareStatement(cmd);
						rs = ps.executeQuery();
						if (rs.absolute(i)) {
							postID = rs.getInt(2);
							message = rs.getString(3);
							posttime = rs.getInt(4);
							fromID = rs.getInt(5);
							name2 = rs.getString(6);
						}
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			%>

			<script type="text/javascript">
				$(document).ready(
						function() {$("#stexpand<%out.print(postID);%>").oembed("<%out.print(message);%>", {
										maxWidth : 400,
										maxHeight : 300
									});
						});
			</script>

			<div class="stbody" id="stbody<%out.print(postID);%>">

				<div class="stimg">

					<!-- TODO: change image -->
					<% int fromIDForDP = Post.getFromIDUsingPostID(postID);
					%>
					<img src="<%="userprofiles/"+fromIDForDP+".jpg" %>" class='big_face' />
				</div>
				<div class="sttext">
					
					
					<a class="stdelete" href="#" id="<%out.print(postID);%>"
						title="Delete update"><%if ((Integer) session.getAttribute("userID") == profileID2 || Post.getFromIDUsingPostID(postID)==(Integer) session.getAttribute("userID")){ %>X<%} %></a> <b> 
						<a href= <%out.println("/UBCDatingServer/profile.jsp?id="+fromIDForDP); %>>
						<% out.print(name2); %>
 						</a>
					</b>
					<%
						out.print(message);
					%>

					<!-- TODO: change time and id -->
					<div class="sttime">
						<%
							PostTime pt = new PostTime();
							out.print(pt.postTimeMessage(posttime));
						%>
<%-- 						| <a href='#' class='commentopen' id='<%out.print(postID);%>'
							title='Comment'>Comment </a> --%>
					</div>
<%--
					<div id="stexpandbox">

						<div id="stexpand<%out.print(postID);%>"></div>
					</div>
 --%>
<%-- 					<div class="commentcontainer"
						id="commentload<%out.print(postID);%>"></div>
					<div class="commentupdate" style='display: none'
						id='commentbox<%out.print(postID);%>'>
						<div class="stcommentimg">

							<!-- TODO: image needs to change -->
							<img src="images/user3.jpg" class='small_face' />
						</div>
						<div class="stcommenttext">
							<form method="post" action="">

								<textarea name="comment" class="comment" maxlength="200"
									id="ctextarea<%out.print(postID);%>"></textarea>
								<br /> <input type="submit" value=" Comment "
									id="<%out.print(postID);%>" class="comment_button" />
							</form>
						</div>
					</div> --%>
				</div>
			</div>
			<%
				}
			%>
		</div>